package com.aaron.kjviewutils.widget;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.aaron.kjviewutils.BaseActivity;
import com.aaron.kjviewutils.R;
import com.aaron.kjviewutils.eventBus.EventBusMsg;
import com.aaron.kjviewutils.spinkit.PoponDismissListener;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Aaron on 2017/3/6.
 */

public class BottomPopWin extends PopupWindow {

    private Context context;
    private Activity aty;

    public
    BottomPopWin ( Context context, Activity aty) {
        this.context = context;
        this.aty = aty;
    }

    public
    void showUi (MsgType type, final EventBus eventBus) {
        View view = null;
        switch (type)
        {
            case MSG_SHARE:
            {
                view = LayoutInflater.from ( context ).inflate (
                        R.layout.pop_share,
                        null
                );
                RelativeLayout shareWechat = (RelativeLayout) view.findViewById(R.id.shareWechat);
                RelativeLayout shareMoments = (RelativeLayout) view.findViewById(R.id.shareMoments);
                shareWechat.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(null!=eventBus)
                        {
                            dismissView();
                            eventBus.post(new EventBusMsg(EventBusMsg.EventBusType.SHARE_WECHAT));
                        }
                    }
                });
                shareMoments.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(null!=eventBus)
                        {
                            dismissView();
                            eventBus.post(new EventBusMsg(EventBusMsg.EventBusType.SHARE_MOMENTS));
                        }
                    }
                });
            }
            break;
            default:
                break;
        }

        // 设置SelectPicPopupWindow的View
        this.setContentView ( view );
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth (WindowManager.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight (WindowManager.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        BaseActivity.backgroundAlpha(aty, 0.4f);
    }

    public void dismissView()
    {
        setOnDismissListener ( new PoponDismissListener( aty ) );
        dismiss ();
    }

    public enum MsgType
    {
        MSG_SHARE;
    }
}
